var baseUrl = "http://192.168.4.18:3000/"
function ajax({
    url,
    method="get",
    success
}){
    var xhr = new XMLHttpRequest()
    xhr.open(method,url=baseUrl+url,true)
    xhr.send()
    xhr.onreadystatechange = function(){
        if(xhr.readyState == 4 && xhr.status == 200){
            var res = JSON.parse(xhr.responseText)
            success(res)
        }
    }
}

function httpAlbum(callback){
    var id = location.search.split("=")[1];
    ajax({
        url:`playlist/detail?id=${id}`,
        success:res =>{
            callback(res)
        }
    })
}
function handleData(res){
    
    var arr = res.playlist;
        // console.log(arr);
        // arr.forEach(arr =>{
            var shou = arr.subscribedCount;
            if(shou>=10000){
                shou = Math.floor(shou/10000)+"万"
            }
            
            var template = `
         
                    <div class ="cover"> 
                    <img class="cover-img" src ="${arr.coverImgUrl}" alt="">
                    <div class="right-content">
                        <div class="text-right-one">
                            <img src="images/新碟专辑.png" alt="">
                            <span class="title">${arr.name}</span>
                        </div>
                        <div class="text-right-two">
                            <img class="img-logo"  alt="">
                            <a href="" class="wyy">网易云音乐</a>
                            <span class="des">2020-06-05创建</span>
                        </div>
                        <div class="text-right-three">
                            <div class="bf">
                                <img src="images/播放.png">
                            </div>
                            <div class="sc">
                                <img src="images/sc.png">
                                <span class="subscribed">(${shou})</span>
                            </div>
                            <div class="zf">
                                <img alt="" src="images/zf.png">
                                <span class="zhuanfa">(${arr.shareCount})</span>
                            </div>
                            <div class="xz">
                                <img alt="" src="images/xz.png">
                                <span class="xiazai">下载</span>
                            </div>
                            <div class="pl">
                                <img alt="" src="images/pl.png">
                                <span class="ping">(${arr.commentCount})</span>
                            </div>
                        </div>
                        
                        <div class="text-right-bottom">    
                            <p class="biao">标签：<span class="tags">${arr.tags}</span></p>            
                            
                            <p class="des">介绍：${arr.description}</p>
                        </div>
                    </div>
                    <div class="list">
                        <div class="list-top">
                            <div class="top-left">
                                <span class="gqlb">歌曲列表</span>
                                <span class="shouge">35首歌</span>
                            </div>
                            <div class="top-right">
                                <a class="shengcheng">生成外链播放器</a>
                                <a class="playcount">播放：<span class="shuzi">${arr.playCount}</span>次</a>
                            </div>
                        </div>
                    </div>
                </div>
            
           
            `
            
            

            $(".head").append(template)
            var reg = res.playlist.tracks
            // console.log(reg)
            reg.forEach((item,index) => {
                var shichang = item.dt;
                // console.log(shichang)
                function handleTime(value){
                    if(value<10){
                        return "0"+value;
                    }
                    return ""+value;
                }
                var seconds = Math.floor(shichang/1000);//转换成秒
                var minutes = handleTime(Math.floor(seconds/60))
                seconds=handleTime(seconds%60);
                var sum = minutes+":"+seconds;
                // console.log(sum)
                
                
                        // console.log(arr.tracks[i].id)
                        var htmlreg = `
                        
                        <li id="more">
                            <span class="no no-top">${index+1}</span>
                            <div class="ho">
                            <a href = "html/detail2.html?id=${item.id}" class="nm s-fc0 f-thide">${item.name}</a>
                            <a class="nm s-fc0 f-thide">${sum}</a>
                            <a class="nm s-fc0 f-thide">${item.ar[0].name}</a>
                            <a class="nm s-fc0 f-thide">${item.al.name}</a>
                            </div>
                            
                        </li>
                `
                $(".li-list").append(htmlreg)

                   
                    
                    
                
                
                
                
                // console.log(item)
                
            })
            
        // })
}
